#include <iostream>
#include <algorithm>
#include <queue>
#include <stdlib.h>
using namespace std;
typedef struct node
{
	char dada;
	node *lchild,*rchild;
}BiTnode,*BiTree;
BiTree CreatBiTree()
{
	char ch;BiTree T;
	cin>>ch;
	if(ch=='#') T=NULL;
	else
	{
		T=(BiTree)malloc(sizeof(BiTnode));
		T->dada=ch;
		T->lchild=CreatBiTree();
		T->rchild=CreatBiTree();
	}
	return T;
}
void func(BiTree T)
{
	if(T!=NULL)
	{
		queue<BiTree>q;
		q.push(T);
		while(!q.empty())
		{
			BiTree now;
			now=q.front();
			q.pop();
			if(now->lchild!=NULL)
				q.push(now->lchild);
			if(now->rchild!=NULL)
				q.push(now->rchild);
			cout<<now->dada;
		}
	}
}
int main()
{
	BiTree T=CreatBiTree();
	func(T);
	return 0;
}